package com.asdf.db.operations.companyclub;

import java.util.List;

import com.asdf.db.operations.IDBOperation;
import com.asdf.db.results.ResultStatus;
import com.asdf.db.results.companyclub.CompanyClubResult;
import com.asdf.entities.CompanyClub;

/** Operation for inserting a company club.
 * @author so4i2014
 *
 */
public class InsertCompanyClub implements IDBOperation< CompanyClubResult>
{

	private List< CompanyClub> companyClubDataSource = null;
	private CompanyClub companyToInsert = null;
	
	/** Create a new operation.
	 * @param source - a list we are going to insert into.
	 */
	public InsertCompanyClub( List< CompanyClub> source)
	{
		companyClubDataSource = source;
	}
	
	/** Set the company club we gonna insert.
	 * @param companyClub
	 */
	public void setCompanyClub(CompanyClub  companyClub)
	{
		companyToInsert = companyClub;
	}
	
	/* (non-Javadoc)
	 * @see com.asdf.db.operations.IDBOperation#perform()
	 */
	@Override
	public CompanyClubResult perform( )
	{
		CompanyClubResult result = new CompanyClubResult( );
		if ( companyClubDataSource.contains( companyToInsert))
		{
			result.setStatus( ResultStatus.AlreadyExist);
		}
		else
		{
			companyClubDataSource.add( companyToInsert);
			result.setStatus( ResultStatus.OK);
		}
		return result;
	}

}
